# 定义 roll 函数
roll <- function(){
  dice_faces <- 1:6
  #probabilities <- c(1/6, 1/6, 1/6, 1/6, 1/6, 1/6)
  #result <- sample(dice_faces, size = 2, prob = probabilities, replace = TRUE)
  result <- sample(dice_faces, size = 2, replace = TRUE)
  return (sum(result))
}

#随着投掷次数的增加，各个部分的方形图也趋近于相同
a<-replicate(10,roll())
library(ggplot2)
qplot(a,binwidth=1)
a<-replicate(100,roll())
qplot(a,binwidth=1)
a<-replicate(10000,roll())
qplot(a,binwidth=1)

